/*
 * configure.cpp - general configure qcarpc widget
 *
 * Copyright (C) 2010-2011 Serge Begger
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "configure.h"
#include "ui_configure.h"

configure::configure(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::configure)
{
    ui->setupUi(this);

    genPanel = new general(this);
    ui->stackedWidget->addWidget(genPanel);

    atfPanel = new autvfmSet(this);
    ui->stackedWidget->addWidget(atfPanel);

    hfsPanel = new hfsset(this);
    if (hfsPanel->btActive)
        ui->stackedWidget->addWidget(hfsPanel);
    else
        hfsPanel->hide();

    frssmPanel = new freessmcfg(this);
    ui->stackedWidget->addWidget(frssmPanel);

    powerPanel = new powerconf(this);
    if (powerPanel->deviceEnabled()) {
        ui->stackedWidget->addWidget(powerPanel);
        connect( ui->pb_rereadPowerConf, SIGNAL(pressed()), powerPanel, SLOT(rereadData()));
        connect( ui->pb_savePowerConf, SIGNAL(pressed()), powerPanel, SLOT(writeData()));
    } else
        powerPanel->hide();

    ui->stackedWidget->setCurrentWidget(genPanel);
    switchPanel();

    connect(hfsPanel, SIGNAL(connectDevice()),this, SLOT(connectHFSDevice()));
    connect(hfsPanel, SIGNAL(disconnectDevice()),this, SLOT(disconnectHFSDevice()));

    connect(ui->closeButton, SIGNAL(pressed()),this,SLOT(closeConfigure()));
}

configure::~configure()
{
    atfPanel->~autvfmSet();
    delete ui;
}

void configure::closeConfigure()
{
    this->~configure();
}

void configure::connectHFSDevice()
{
    emit connHFSDev();
}

void configure::disconnectHFSDevice()
{
    emit disconnHFSDev();
}

void configure::on_nextButton_pressed()
{
    int max  = ui->stackedWidget->count();
    int curr = ui->stackedWidget->currentIndex();
    if(curr == max)
        return;
    ui->stackedWidget->setCurrentIndex(curr+1);
    switchPanel();
}

void configure::on_prevButton_pressed()
{
    int curr = ui->stackedWidget->currentIndex();
    if(curr == 0)
        return;
    ui->stackedWidget->setCurrentIndex(curr-1);
    switchPanel();
}

void configure::switchPanel()
{
    QWidget *currWidget = ui->stackedWidget->currentWidget();
    if (currWidget == genPanel)
        ui->iconLabel->setPixmap(QPixmap(QString::fromUtf8(":/buttons/res/galternatives.png")));
    else if(currWidget == atfPanel)
        ui->iconLabel->setPixmap(QPixmap(QString::fromUtf8(":/buttons/res/multimedia.png")));
    else if(currWidget == hfsPanel)
        ui->iconLabel->setPixmap(QPixmap(QString::fromUtf8(":/buttons/res/bluetooth.png")));
    else if(currWidget ==  frssmPanel)
        ui->iconLabel->setPixmap(QPixmap(QString::fromUtf8(":/buttons/res/gpm-statistics.png")));
    else if(currWidget == powerPanel)
        ui->iconLabel->setPixmap(QPixmap(QString::fromUtf8(":/buttons/res/gnome-power-preferences.png")));


    ui->pb_rereadPowerConf->setVisible((currWidget == powerPanel));
    ui->pb_savePowerConf->setVisible((currWidget == powerPanel));
    ui->prevButton->setDisabled((ui->stackedWidget->currentIndex() == 0));
    ui->nextButton->setDisabled((ui->stackedWidget->currentIndex() == ui->stackedWidget->count()-1));
}
